package com.mapper;

import com.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeMapper {
    // 数据处理层
    // 查询所有员工
    @Select("select * from emp;")
    List<Employee> selectEmployeeAll();

    // 查询一个员工
    @Select("select * from emp where empno = #{id}")
    Employee selectEmployeeById(int id);

    // 查询员工姓名
    @Select("select * from emp where ename like '%${ename}%'")
    Employee selectEmployeeByName(String name);

    // 新增一个员工
    @Insert("INSERT INTO `emp` (ename, job, mgr, hiredate,sal, comm, deptno) VALUES (#{ename}, #{job}, #{mgr}, #{hiredate},#{sal}, #{comm}, #{deptno});")
    int insertEmployee(Employee employee);

    // 修改一个员工
    @Update("update `emp`\n" +
            "        set ename   = #{ename},\n" +
            "            job=#{job},\n" +
            "            mgr=#{mgr},\n" +
            "            hiredate=#{hiredate},\n" +
            "            sal=#{sal},\n" +
            "            comm= #{comm},\n" +
            "            deptno  = #{deptno}\n" +
            "        where empno = #{empno};")
    int updateEmployeeById(Employee employee);

    // 删除一个员工
    @Delete("delete from emp where empno = #{empno};")
    int deleteEmployeeById(int id);
}
